/**
 * 本文件是一个简单的单例设计模式的实现
 */

class Singleton{
    constructor(){
        //阻止new
        if(new.target){
            throw new Error(`This is a singleton object, you cannot use new keyword!
            You shoule use method getInstance() to get the instance!`)
        }
    }

    static getInstance(){
        if(!Singleton.instance){
            Singleton.instance = {}
            Singleton.instance.__proto__ = Singleton.prototype
        }
        return Singleton.instance
    }

    getMsg(){
        console.log('msg')
    }
}

let obj = Singleton.getInstance()
obj.getMsg()